package middleware

import (
	"admin-system/internal/service"
	"github.com/gin-gonic/gin"
)

// 注册中间件所需要的服务
type MiddlewareContainer struct {
	svc            *service.Service
	authMiddleware gin.HandlerFunc
	RbacMiddleware gin.HandlerFunc
	RequestPreload gin.HandlerFunc
}

func NewMiddleware(svc *service.Service) *MiddlewareContainer {
	return &MiddlewareContainer{
		authMiddleware: AuthMiddleware(),
		RbacMiddleware: RbacMiddleware(svc.Permission),
		RequestPreload: FixEmptyIDMiddleware(),
	}
}

func (m *MiddlewareContainer) AuthMiddleware() gin.HandlerFunc {
	return m.authMiddleware
}

func (m *MiddlewareContainer) RBACMiddleware() gin.HandlerFunc {
	return m.RbacMiddleware
}

func (m *MiddlewareContainer) FixEmptyIDMiddleware() gin.HandlerFunc {
	return m.RequestPreload
}
